package com.purong.purong.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.purong.purong.R;


/**
 * Created by Administrator on 2016/8/4.
 */
public class ConfirmDialog extends Dialog{
    private Context mContext;
    private onConfirmClickListenr mListener;
    private String msg;
    private boolean showCancel=true;
    public ConfirmDialog(Context context, String msg, onConfirmClickListenr listenr) {
        super(context, R.style.DialogTransparent);
        this.mContext=context;
        this.mListener=listenr;
        this.msg=msg;
        setCanceledOnTouchOutside(true);

    }
    public void showCancel(boolean isShow){
        this.showCancel=isShow;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        View inflate = LayoutInflater.from(mContext).inflate(R.layout.dialog_confirm, null);
        setContentView(inflate);
        TextView msg=(TextView)inflate.findViewById(R.id.msg);
        msg.setText(this.msg);
        if (!showCancel){
            findViewById(R.id.cancel).setVisibility(View.GONE);
            findViewById(R.id.cut_line).setVisibility(View.GONE);
        }
        findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                if (mListener!=null){
                    mListener.onCancel();
                }
            }
        });
        findViewById(R.id.confirm).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                if (mListener!=null){
                    mListener.onConfirm();
                }
            }
        });
    }
    public interface onConfirmClickListenr{
        void onConfirm();
        void onCancel();
    }
}
